﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
    <script src="/lib/date/wdatepicker.js"></script>
    <link href="/lib/select2/select2.min.css" rel="stylesheet" />
    <script src="/lib/select2/select2.min.js"></script>
</head>
<body style="background-color: white;">
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form" onsubmit="return false;">
            <div class="tab-content">
                <input type="hidden" name="id" value="0">
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>公司名称：</label>
                    <div class="wd250 m15_l">
                        <select class="form-control" name="companyId"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>匹配时间(-分)：</label>
                    <div class="wd250 m15_l">
                        <input class="form-control" type="text" name="matchMinusMinute" maxlength="5" autocomplete="off" placeholder="匹配时间(-分)介于 -1440 和 0 之间">
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>匹配时间(分)：</label>
                    <div class="wd250 m15_l">
                        <input class="form-control" type="text" name="matchMinute" maxlength="4" autocomplete="off" placeholder="匹配时间介于 10 和 1440 之间">
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">收款银行：</label>
                    <div class="wd250 m15_l">
                        <select class="form-control bankCode" type="text" name="matchBankCode" maxlength="40" autocomplete="off" multiple="multiple"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">交易类型：</label>
                    <div class="wd250 m15_l">
                        <select class="form-control bankTranstype" type="text" name="matchTranstype" maxlength="40" autocomplete="off" multiple="multiple"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>推送条件：</label>
                    <div class="wd250 m15_l">
                        <input id="matchPushSuccess" name="matchPushSuccess" type="checkbox" value="1" /> <label for="matchPushSuccess">匹配成功</label>
                        <input id="matchPushFail" name="matchPushFail" type="checkbox" value="2" /> <label for="matchPushFail">匹配失败</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>匹配规则：</label>
                    <div class="wd300 m15_l">
                        <input type="checkbox" name="matchRule" value="1" /> 姓名
                        <input type="checkbox" name="matchRule" value="2" /> 金额
                        <input type="checkbox" name="matchRule" value="3" /> 客户卡号
                        <input type="checkbox" name="matchRule" value="4" /> 附言
                        <input type="checkbox" name="matchRule" value="5" /> 收款卡号
                    </div>
                </div>
                <div class="form-group" style="margin-top:-10px; line-height:20px;">
                    <div style="margin-left:100px;">
                        1、姓名与金额,两个必须需选一个,必选匹配的条件<br />
                        2、卡号与附言是铺助条件,存款订单里有,则再匹配<br />
                        3、必选匹配条件,只选择金额时,商户需限制玩家在<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 匹配时间内不可重复金额<br />
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">备注：</label>
                    <div class="wd250 m15_l">
                        <input class="form-control" type="text" name="matchRemark" maxlength="40" autocomplete="off" placeholder="长度必须介于 3 和 40 之间">
                    </div>
                </div>
            </div>
        </form>
    </section>

    <script type="text/javascript">
        function init(id) {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/DepositMatchRule/GetAddOrEdit/" + id,
                data: null,
                success: function (response) {
                    if (response) {

                        //公司
                        var companyId = $("select[name='companyId']");
                        common(companyId, response.companyResponse, 0);

                        //银行
                        var matchBankCode = $("select[name='matchBankCode']");
                        common(matchBankCode, response.bankInfoResponse, 1);

                        //系统配置
                        var matchTranstype = $("select[name='matchTranstype']");
                        common(matchTranstype, response.sysConfigTypeList, 2);

                        if (response.id <= 0) {
                            $("input[name='matchPushSuccess']").attr("checked", true);
                            $("input[name='matchPushFail']").attr("checked", true);
                        } else {
                            if (response.matchPushRule>0) {
                                if (response.matchPushRule == 1) {
                                    $("input[name='matchPushSuccess']").attr("checked", true);
                                } else if (response.matchPushRule == 2) {
                                    $("input[name='matchPushFail']").attr("checked", true);
                                } else if (response.matchPushRule == 3) {
                                    $("input[name='matchPushSuccess']").attr("checked", true);
                                    $("input[name='matchPushFail']").attr("checked", true);
                                }
                            }
                        }

                        if (response.companyId > 0) {
                            companyId.val(response.companyId);
                        }
                        if (!FlashPay.Util.isNullOrEmptySpance(response.matchBankCode)) {
                            let arr = response.matchBankCode.split(",");
                            matchBankCode.val(arr).trigger("change");
                        }
                        if (!FlashPay.Util.isNullOrEmptySpance(response.matchTranstype)) {
                            let arr = response.matchTranstype.split(",");
                            matchTranstype.val(arr).trigger("change");
                        }

                        FlashPay.Util.SetInputVal("id", response.id);
                        FlashPay.Util.SetInputVal("matchMinute", response.matchMinute > 0 ? response.matchMinute : 30);
                        FlashPay.Util.SetInputVal("matchMinusMinute", response.matchMinusMinute < 0 ? response.matchMinusMinute : '');
                        FlashPay.Util.SetInputVal("matchRemark", response.matchRemark);

                        if (!FlashPay.Util.isNullOrEmptySpance(response.matchRule)) {
                            var matchRuleArray = response.matchRule.split(',');
                            for (var i = 0; i < matchRuleArray.length; i++) {
                                $('input[name="matchRule"][value="' + matchRuleArray[i] + '"]').prop('checked', true);
                            }
                        }
                    }
                    cover.Remove();
                },
                error: function (e) {
                    cover.Remove();
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试。");
                }
            });
        }

        function common(obj, data, type) {
            if (data != null) {
                obj.empty();
                obj.append("<option value=''>请选择</option>");
                $.each(data, function (i, item) {
                    if (type == 0) {
                        obj.append("<option value='" + item.companyID + "'>" + item.companyName + "</option >");
                    } else if (type == 1) {
                        obj.append("<option value='" + item.bankCode + "'>" + item.bankName + "</option >");
                    } else if (type == 2) {
                        obj.append("<option value='" + item.configValue + "'>" + item.configContent + "</option >");
                    }
                });
            }
        }

        $(function () {
            var id = FlashPay.Util.GetQueryString("id");
            init(id);
            $('.bankCode').select2({ placeholder: '选择匹配银行'});
            $(".bankTranstype").select2({ placeholder: '选择交易类型'});
        })

        function save() {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            var data = $("#form").serializeObject();
            matchRule = [];

            $("input[name='matchRule']:checked").each(function () {
                matchRule.push($(this).val());
            });
            data.depositType = matchRule.join(',');

            FlashPay.Util.Ajax({
                url: '/DepositMatchRule/DepositMatchRuleAddOrEdit',
                type: 'POST',
                data: data,
                success: function (response) {
                    if (response.success) {
                        cover.Remove();
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        cover.Remove();
                        FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                    }
                },
                error: function (json) {
                    cover.Remove();
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试。");
                }
            });
        }

        function cancel() {
            FlashPay.UI.CloseDialog();
        }

        $.fn.serializeObject = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };
    </script>
</body>
</html>